package com.t2t.top.devops.utils;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.util.Properties;

@Slf4j
@Data
public class VersionUtils {

    private String version;
    private String groupId;
    private String artifactId;

    private static VersionUtils instance;

    private VersionUtils() {
        loadConfiguration();
    }

    public static VersionUtils getInstance() {
        if (instance == null) {
            instance = new VersionUtils();
        }
        return instance;
    }

    private void loadConfiguration() {
        Properties properties = new Properties();
        InputStream in = null;
        try {
            in = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties");
            if (in != null) {
                properties.load(in);
                version = properties.getProperty("version");
                groupId = properties.getProperty("groupId");
                artifactId = properties.getProperty("artifactId");
            }
        } catch (Exception e) {
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                }
            }
        }
    }

}
